layui.define([ 'form', 'laydate', 'table' ], function(exports) {
    var form = layui.form;
    var laydate = layui.laydate;
    var table = layui.table;
    var rentingTable = null;
    var view ={
        init:function(){
            this.initTable();
            this.initSearchForm();
            this.initToolBar();
            window.dataReload = function(){
                Lib.doSearchForm($("#searchForm"),rentingTable)
            }
        },
        initTable:function(){
            rentingTable = table.render({
                elem : '#rentingTable',
                height : Lib.getTableHeight(1),
                cellMinWidth: 100,
                method : 'post',
                url : Common.ctxPath + '/cms/renting/list.json' // 数据接口
                ,page : Lib.tablePage // 开启分页
                ,limit : 10,
                cols : [ [ // 表头
                    {
                        type : 'checkbox',
                        fixed:'left',
                    },

                {

                    field : 'name', 
                        title : '姓名',
                    align: 'center',
                    width:"165"
                },
                {

                    field : 'year',
                    title : '年度',
                    align: 'center',
                    width:"90"
                },
                {

                     field : 'declarationGradeText',
                     title : '申报档次',
                    align: 'center',
                    width:"90"
                 },
                 {

                     field : 'numberDeclarations',
                     title : '申报月数',
                     align: 'center',
                     width:"90"
                 },
                 {

                        field : 'totalAmount',
                        title : '合计金额',
                     align: 'right',
                     width:"135",templet:function (d) {
                     return Common.getMoney(d.totalAmount);
                 }
                 },

                {

                    field : 'businessState',
                        title : '业务状态',
                    align: 'center',
                    width:"135"
                },

                {

                    field : 'creationDate',
                        title : '创建日期',
                    align: 'center',
                    width:"180"
                }/*, {
                    field : 'handlingSuggestion',
                    title : '审核意见',
                    align: 'left',
                    width:"180"
                 }*/
        ] ]

        });

            table.on('checkbox(rentingTable)', function(obj){
                var renting = obj.data;
                if(obj.checked){
                    //按钮逻辑Lib.buttonEnable()
                }else{

                }
            })
        },

        initSearchForm:function(){
            Lib.initSearchForm( $("#searchForm"),rentingTable,form);
        },
        initToolBar:function(){
            toolbar = {
                add : function() { // 获取选中数据\
                    Common.post("/cms/common/notLeave.json?declarationType=renting", {}, function(data) {
                        var url = "/cms/renting/add.do";
                        Common.openDlg(url, "租房补贴>新增");
                    })
                },
                edit : function() { // 获取选中数目
                    var data = Common.getObtainState(table,"rentingTable");
                    if(data==null){
                        return ;
                    }
                    var url = "/cms/renting/edit.do?id="+data.id;
                    Common.openDlg(url,"租房补贴>编辑");
                },
                find : function() { // 获取选中数目
                    var data = Common.getOneFromTable(table,"rentingTable");
                    if(data==null){
                        return ;
                    }
                    var url = "/cms/renting/findenterprise.do?id="+data.id;
                    Common.openDlg(url,"租房补贴受理>查看");
                },
                process : function() { // 获取选中数目
                    var businessType = Common.businessType.renting;
                    var data = Common.getOneFromTable(table,"rentingTable");
                    if(data==null){
                        return ;
                    }
                    var url = "/cms/businessProcess/index.do?businessType="+businessType+"&businessId="+data.id;
                    Common.openDlg(url,"流程信息>编辑");
                },
                del : function() {
                    layui.use(['del'], function(){
                        var delView = layui.del;
                        delView.delBatch();
                    });
                }
        };
            $('.ext-toolbar').on('click', function() {
                var type = $(this).data('type');
                toolbar[type] ? toolbar[type].call(this) : '';
            });
        }
    }
    exports('index',view);

});